package thread2;

import java.util.*;

public class Fifo {
	List<String> l;
	
	public Fifo(){
		l = new ArrayList<String>(10);
	}
	
	
	
	
	
	public void put(String s0) throws Exception{
		
		
		
		synchronized(this){
			System.out.println(Thread.currentThread().getName() + " is using Fifo's put");
			if (l.size() == 10) {	
					this.wait();
			}
			else{
				l.add(s0);
				this.notifyAll();
			}
			
			
		}
	}
	
	public String get() throws Exception{
		String r;
		synchronized(this){
			System.out.println(Thread.currentThread().getName() + "is using Fifo's get");
			if (l.isEmpty()) {
				this.wait();
			}
			r = l.get(0);
			l.remove(0);
			this.notifyAll();
		}
		return r;
	}
}